package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.GoodsmDao;
import io.renren.dto.GoodsmDTO;
import io.renren.entity.GoodsmEntity;
import io.renren.service.GoodsmService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-05-30
 */
@Service
public class GoodsmServiceImpl extends CrudServiceImpl<GoodsmDao, GoodsmEntity, GoodsmDTO> implements GoodsmService {

    @Override
    public QueryWrapper<GoodsmEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<GoodsmEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public String findNameByGoodsMOIDs(List<String> goodsMOIDs) {
        QueryWrapper<GoodsmEntity> wrapper = new QueryWrapper<>();
        wrapper.in("GoodsMOID", goodsMOIDs);
        List<GoodsmEntity> list = baseDao.selectList(wrapper);
        if (list != null && list.size() > 0) {
            return list.stream().map(GoodsmEntity::getName).reduce((a, b) -> a + "," + b).get();
        }
        return "";
    }
}